package com.example.chasshelper.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.chasshelper.R;
import com.example.chasshelper.SubjectStuActivity;
import com.example.chasshelper.SubjectTeaActivity;
import com.example.chasshelper.dao.ClassroomDao;
import com.example.chasshelper.dao.CourseDao;
import com.example.chasshelper.dao.MessageDao;
import com.example.chasshelper.dao.RegistrationDao;
import com.example.chasshelper.dao.SolutionDao;
import com.example.chasshelper.dao.StudentDao;
import com.example.chasshelper.dao.TeacherDao;
import com.example.chasshelper.dao.TestDao;
import com.example.chasshelper.model.Course;
import com.example.chasshelper.model.Student;
import com.example.chasshelper.utils.DaoUtils;

import java.util.ArrayList;
import java.util.List;

public class SubjectStuAdapter extends RecyclerView.Adapter<SubjectStuAdapter.SubjectStuViewHolder>{
    private Context mContext;
    //数据
    private List<Course> list;
    private Student student;
    //dao
    private TeacherDao teacherDao= DaoUtils.getTeacherDao();
    private StudentDao studentDao=DaoUtils.getStudentDao();
    private CourseDao courseDao=DaoUtils.getCourseDao();
    private ClassroomDao classroomDao=DaoUtils.getClassroomDao();
    private RegistrationDao registrationDao=DaoUtils.getRegistrationDao();
    private SolutionDao solutionDao = DaoUtils.getSolutionDao();
    private MessageDao messageDao = DaoUtils.getMessageDao();
    private TestDao testDao = DaoUtils.getTestDao();

    public SubjectStuAdapter(Context mContext, List<Course> list,Student student) {
        this.mContext = mContext;
        this.list = list;
        this.student = student;
    }
    public void setList(List<Course> list) {
        this.list = list;

    }

    @NonNull
    @Override
    public SubjectStuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //绑定布局
        SubjectStuAdapter.SubjectStuViewHolder subjectStuViewHolder = new SubjectStuAdapter.SubjectStuViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_subjec_rv_stu, parent, false));
        return subjectStuViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull SubjectStuViewHolder holder, int position) {
        //回显
        Course course = list.get(position);
        holder.tv_id.setText("课程id："+String.valueOf(course.getCourseId()));
        holder.tv_name.setText("课程名："+course.getCourseName());
        holder.tv_time.setText("创建时间："+course.getCourseTime());
        holder.tv_teacher.setText("授课教师："+courseDao.findTeacher(course).getTeacherName());
        //点击事件
        holder.ll_oneCourse.setOnClickListener(new View.OnClickListener() {//进入课程页面
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("course", course);
                intent.putExtra("student", student);
                intent.setClass(mContext, SubjectStuActivity.class);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        //返回item数量
        return list.size();
    }


    class SubjectStuViewHolder extends RecyclerView.ViewHolder{
        //控件
        LinearLayout ll_oneCourse;
        TextView tv_id;
        TextView tv_name;
        TextView tv_time;
        TextView tv_teacher;
        public SubjectStuViewHolder(@NonNull View itemView) {
            super(itemView);
            //绑定控件
            ll_oneCourse = itemView.findViewById(R.id.ll_oneCourse);
            tv_id = itemView.findViewById(R.id.tv_id);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_time = itemView.findViewById(R.id.tv_time);
            tv_teacher = itemView.findViewById(R.id.tv_teacher);
        }
     }
}
